class Turntable {
    constructor(image, x, y, rotationSpeed) {
        this.bitmap = new createjs.Bitmap(image);
        this.bitmap.regX = image.width / 2;
        this.bitmap.regY = image.height / 2;
        this.bitmap.x = x;
        this.bitmap.y = y;
        this.rotationSpeed = rotationSpeed;
        this.isRotating = false;
    }

    rotateTo(targetRotation, duration) {
        createjs.Tween.get(this.bitmap)
            .to({ rotation: targetRotation }, duration, createjs.Ease.quadOut)
            .call(() => { this.isRotating = false; });
    }

    update() {
        if (this.isRotating) {
            this.bitmap.rotation += this.rotationSpeed;

            if (this.bitmap.rotation >= 1080) {
                
                console.log("The turntable has rotated 3 circles ", this.bitmap.rotation, this.isRotating);
                this.isRotating = false;
                this.rotateTo(1260, 2000)
            }
        }
    }
}

export default Turntable;
